package com.ruoyi.project.para.account.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.project.oms.paeaAuType.service.IPaeaAuTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.para.account.domain.ParaKeyAccount;
import com.ruoyi.project.para.account.service.IParaKeyAccountService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 重点账户Controller
 *
 * @author ruoyi
 * @date 2020-04-06
 */
@Controller
@RequestMapping("/para/account")
public class ParaKeyAccountController extends BaseController
{
    private String prefix = "para/account";

    @Autowired
    private IParaKeyAccountService paraKeyAccountService;
    @Autowired
    private IPaeaAuTypeService paeaAuTypeService;

    @RequiresPermissions("para:account:view")
    @GetMapping()
    public String account(ModelMap mmap)
    {
        mmap.put("auTypes", paeaAuTypeService.selectPaeaAuTypeAll());
        return prefix + "/account";
    }

    /**
     * 查询重点账户列表
     */
    @RequiresPermissions("para:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ParaKeyAccount paraKeyAccount)
    {
        startPage();
        List<ParaKeyAccount> list = paraKeyAccountService.list(new QueryWrapper<>(paraKeyAccount));
        return getDataTable(list);
    }

    /**
     * 导出重点账户列表
     */
    @RequiresPermissions("para:account:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ParaKeyAccount paraKeyAccount)
    {
        List<ParaKeyAccount> list = paraKeyAccountService.list(new QueryWrapper<>(paraKeyAccount));
        ExcelUtil<ParaKeyAccount> util = new ExcelUtil<ParaKeyAccount>(ParaKeyAccount.class);
        return util.exportExcel(list, "account");
    }

    /**
     * 新增重点账户
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("auTypes", paeaAuTypeService.selectPaeaAuTypeAll());
        return prefix + "/add";
    }

    /**
     * 新增保存重点账户
     */
    @RequiresPermissions("para:account:add")
    @Log(title = "重点账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ParaKeyAccount paraKeyAccount)
    {
        return toAjax(paraKeyAccountService.saveOrUpdate(paraKeyAccount));
    }

    /**
     * 修改重点账户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ParaKeyAccount paraKeyAccount = paraKeyAccountService.getById(id);
        mmap.put("paraKeyAccount", paraKeyAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存重点账户
     */
    @RequiresPermissions("para:account:edit")
    @Log(title = "重点账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ParaKeyAccount paraKeyAccount)
    {
        return toAjax(paraKeyAccountService.saveOrUpdate(paraKeyAccount));
    }

    /**
     * 删除重点账户
     */
    @RequiresPermissions("para:account:remove")
    @Log(title = "重点账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paraKeyAccountService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
